{% extends "saltstack/index.html" %}

{% block right_content %}

<div id="right_menu">
    <table id="example" style="table-layout:fixed;text-align: center;" class="table table-bordered table-hover">
        <thead>
            <td>主机</td>
            <td>状态</td>
        </thead>
        {% if salt_key %}
        {% for node in salt_key %}
        <tr>
            <td>{{ node.minions }}</td>
            <td>
            {% ifequal node.status 0 %}
            <div>
                <button  type="button" class="assetReport btn btn-info" data-hostname="{{ node.minions }}"
                                 data-toggle="modal" data-target="#assetReport">上报资产</button>
            </div>
            {% else %}
                {{ node.status_desc }}
            {% endifequal %}
            </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>

    <div>
        <span>跳转到
         <select class="pagei">
             {% for temppage in page_list %}
             <option value="{{ temppage }}" {% ifequal temppage page %}selected {% endifequal %}>{{ temppage }}</option>
             {% endfor %}
         </select>页
        </span>
        <span style="padding-left: 28%;">每页{{ page_num }}条，第{{ page }}页，共{{ count }}条，共{{ page_total }}页</span>
        <span style="float:right;padding-right:50px">
            <a class="word hint hint-top" href="{% url 'saltstack:nodeList' %}?page=1" data-hint="首页"><span class="glyphicon glyphicon-fast-backward"></span></a>
            {% ifnotequal page 1 %}
            <a href="{% url 'saltstack:nodeList' %}?page={{ page|add:-1 }}" class="hint hint-top" data-hint="上一页"><span class="glyphicon glyphicon-step-backward"></span></a>
            {% endifnotequal %}
            {% ifnotequal page page_total %}
            <a href="{% url  'saltstack:nodeList' %}?page={{ page|add:1 }}" class="hint hint-top" data-hint="下一页"><span class="glyphicon glyphicon-step-forward"></span></a>
            {% endifnotequal %}
            <a class="word hint hint-top" data-hint="尾页" href="{% url 'saltstack:nodeList' %}?page={{ page_total }}"><span class="glyphicon glyphicon-fast-forward"></span></a>
        </span>
    </div>

</div>

<script type="text/javascript">
    $(".pagei").change(function(){
        var index=$(this).children('option:selected').val();
        window.location.href="{% url 'saltstack:nodeList' %}?page=" + index;
    });

    $(".assetReport").click(function(){
        var hostname = $(this).data("hostname");
        //cpu
        var urls = "{% url 'saltstack:getcmd' %}";
        var salt_cmd = 'dmidecode -t memory|grep -i size |grep -v -E "Maximum|Enabled|Installed"'
        var postdata = {salt_node_name:hostname,comm_shell:'cmd',salt_cmd:salt_cmd}
        var jsonstr = $.ajax({
			    url : urls,
			    type : "POST",
			    data : postdata,
			    async : false,
			    cache : false
			});
		var jsonobj = eval('(' + jsonstr.responseText + ')');
		memory = jsonobj.data;

		//other data info
        var urls = "{% url 'equipment:equniquecheck' %}";
        var postdata = {hostname:hostname}
        var jsonstr = $.ajax({
			    url : urls,
			    type : "POST",
			    data : postdata,
			    async : false,
			    cache : false
			});
	    var jsonobj = eval('(' + jsonstr.responseText + ')');
	    if(jsonobj.status == 1){
	        if(jsonobj.data == false){
	            window.location.href="{% url 'saltstack:assetReport' %}?hostname=" + hostname + "&memory=" + memory;
	        }else{
	            alert('设备已存在');
	        }
	    }else{
	        alert(jsonobj.message);
	    }
    });
</script>
{% endblock %}

